Skip to content

#827 fix boolpredicate validation - #828

Merged
anttiviljami merged 2 commits into
openapistack:mainfrom
walker-sean:fix/827
Jul 29, 2026
Merged

#827 fix boolpredicate validation#828
anttiviljami merged 2 commits into
openapistack:mainfrom
walker-sean:fix/827

Conversation

@walker-sean

@walker-sean walker-sean commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Closes #827

  • OpenAPIBackend constructor fixed to properly assign the validate option as a member.
  • Also renamed BoolPredicate to the more precise, less redundant ContextPredicate
  • Added tests to verify use of predicates as validate value

Copilot AI review requested due to automatic review settings March 2, 2026 23:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes issue #827 where supplying a predicate function for OpenAPIBackend’s validate option was being coerced to true, preventing conditional validation from working.

Changes:

  • Rename BoolPredicate to ContextPredicate and update the validate option/member types accordingly.
  • Fix OpenAPIBackend constructor to preserve the validate option value (boolean or predicate) instead of coercing it.
  • Add tests covering predicate-based validation behavior (skip vs run validation).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/backend.ts Updates predicate type name and fixes validate assignment to avoid boolean coercion.
src/backend.test.ts Adds regression tests ensuring validate predicates are invoked and affect validation flow.
Comments suppressed due to low confidence (1)

src/backend.ts:75

  • Renaming the exported BoolPredicate type to ContextPredicate is a breaking public API change for TypeScript consumers (they may import BoolPredicate today), but the package version is still on the v5 minor line. Consider keeping a backward-compatible alias export (e.g. export type BoolPredicate = ContextPredicate with a @deprecated tag) so existing imports keep compiling while still steering users to the new name.
export type HandlerMap = { [operationId: string]: Handler | undefined };

export type ContextPredicate = (context: Context, ...args: any[]) => boolean;

/**
 * The different possibilities for set matching.
 *
 * @enum {string}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@walker-sean

Copy link
Copy Markdown
Contributor Author

@anttiviljami

@anttiviljami
anttiviljami merged commit 5477414 into openapistack:main Jul 29, 2026

Copy link
Copy Markdown
Member

Thanks for the fix and sorry for the slow response!

Nice catch — I traced the !! back to d92ef21, which shipped in 5.11.0, so predicates have been silently coerced to true ever since. Good tests too.

This'll go out as a minor rather than a patch, since predicates actually taking effect is a real behaviour change for anyone already passing one. I'll follow up with docs for the option.


Generated by Claude Code

@anttiviljami

Copy link
Copy Markdown
Member

This is released as part of openapi-backend@5.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BoolPredicate validate option does not work

3 participants